<?php 
	include 'mysql.php';
	$num = $_POST['sid'];
	echo $timebegin=date("Y-m-d H:i:s");
	$sql1="select worktable.studentid,stationname,studentname,worktable.worktime from allstudent,worktable,station where worktable.studentid=allstudent.studentid and allstudent.studentid='$num' and worktable.stationid=station.stationid";
	$res = mysql_query($sql1);
	$weekarray=array("日","一","二","三","四","五","六");
	$day="星期".$weekarray[date("w")];
	echo $day;
	$m=date("G")-5;
	$m1=date("G")+5;
	$timest=date("Y-m-d")." ".$m.":".date("i:s");
	$timelt=date("Y-m-d")." ".$m1.":".date("i:s");
	while($row=mysql_fetch_array($res)){
	$string2 = explode(';',$row[3]);
		for ($i=0;$i<sizeof($string2);$i++){
		if($string2[0]==$day){
		$string = explode(',',$string2[1]);
		if ($string[0]<$timelt&&$string>$timest){
		$day1=$row[1];
		switch ($day1){
			case '报刊岗':$in="INSERT INTO `newspapers` (`studentid`, `timebegin`) VALUES ('$row[0]', '$timebegin')";
		$re=mysql_query($in);
		echo $re;
		if($re){
		echo '插入成功1！';
		}
		break;
			case '上书岗':
			echo 'here';
			$n="INSERT INTO `bookmanage` (`studentid`, `timebegin`) VALUES ('$row[0]', '$timebegin')";
		$re=mysql_query($n);
		echo $re;
		if($re){
		echo '插入成功2！';
		}
		break;
			case '借、还、分书岗':
			$sql1="select timecount.studentid,timecount.timebegin from timecount where timecount.studentid='$row[0]' and timecount.teachid is NULL";
			$res = mysql_query($sql1);
			if (mysql_num_rows($res)==1){
			break;
			}
			$in="INSERT INTO `timecount` (`studentid`, `timebegin`,`stationid`) VALUES ('$row[0]', '$timebegin','a0')";
		$re=mysql_query($in);
		echo $re;
		if($re){
		echo '插入成功1！';
		}
		break;
			case '书库管理岗':
			$in="INSERT INTO `roommanage` (`studentid`, `timebegin`,`stationid`) VALUES ('$row[0]', '$timebegin','a2')";
		$re=mysql_query($in);
		echo $re;
		if($re){
		echo '插入成功1！';
		}
		break;
			case '小循环':
			$in="INSERT INTO `roommanage` (`studentid`, `timebegin`,`stationid`) VALUES ('$row[0]', '$timebegin','a9')";
		$re=mysql_query($in);
		echo $re;
		if($re){
		echo '插入成功1！';
		}
		break;
			case '机动岗':
			$in="INSERT INTO `timecount` (`studentid`, `timebegin`,`stationid`) VALUES ('$row[0]', '$timebegin','a4')";
		$re=mysql_query($in);
		echo $re;
		if($re){
		echo '插入成功1！';
		}
		break;
	}
	}
		}
}
}
	header("Location:../view/workattend.php");
	exit();
?>